package com.demo.datastructure.binarySearch;

/**
 * @description:
 * @author: ljr
 * @time: 2021/5/11 21:05
 */
public class BinarySearch1{

    public int bsearch(int[] a, int n, int value) {
        int low = 0;
        int high = n-1;
        while(low <= high){
            int mid = low+(high-low)>>1;
             if(a[mid] == value){
                 return mid;
             }else if(a[mid] < value){
                 low = mid+1;
             }else{
                 high = mid-1;
             }
        }
        return -1;
    }

}
